Skip to content

Conversation

@skoob13
Copy link
Contributor

@skoob13 skoob13 commented Oct 24, 2025

Problem

LangChain passes input tokens as a sum of input and cached tokens, so we incorrectly calculate the total cost.

@skoob13 skoob13 requested a review from a team October 24, 2025 10:25
Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

4 files reviewed, no comments

Edit Code Review Agent Settings | Greptile

Co-authored-by: Radu Raicea <radu@raicea.com>
- Updated version to 6.7.12
- Added changelog entry for 6.7.12
- Kept all new tests from both branches
- PR branch: 5 new cache token tests
- Master: 1 new LangChain 1.0+ compatibility test
Master has already released 6.7.12 with other fixes, so this PR will be 6.7.13
@andrewm4894 andrewm4894 enabled auto-merge (squash) November 2, 2025 18:57
@andrewm4894 andrewm4894 merged commit 69293f5 into master Nov 2, 2025
10 checks passed
@andrewm4894 andrewm4894 deleted the fix/langchain-callback-cache-cost-calculation branch November 2, 2025 18:58
carlos-marchal-ph added a commit that referenced this pull request Nov 10, 2025
PR #346 introduced cache token subtraction for all providers, causing
double subtraction for OpenAI/OpenRouter and resulting in negative costs.

The plugin-server only subtracts cache tokens for Anthropic providers
(exact match on provider name or substring match on model name). This
fix aligns the Python SDK with that behavior.

Changes:
- Only subtract cache tokens when provider="anthropic" OR model contains "anthropic"
- Passes provider and model metadata to usage parsing functions
- Updates tests to reflect correct behavior (no subtraction for OpenAI)
- Adds test for Anthropic provider subtraction

Fixes negative cost calculations for users on OpenAI/OpenRouter with cached tokens.
carlos-marchal-ph added a commit that referenced this pull request Nov 10, 2025
PR #346 introduced cache token subtraction for all providers, causing
double subtraction for OpenAI/OpenRouter and resulting in negative costs.

The plugin-server only subtracts cache tokens for Anthropic providers
(exact match on provider name or substring match on model name). This
fix aligns the Python SDK with that behavior.

Changes:
- Only subtract cache tokens when provider="anthropic" OR model contains "anthropic"
- Passes provider and model metadata to usage parsing functions
- Updates tests to reflect correct behavior (no subtraction for OpenAI)
- Adds test for Anthropic provider subtraction

Fixes negative cost calculations for users on OpenAI/OpenRouter with cached tokens.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants